package top.lidee.module.backendApi.twice.management.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.lidee.common.dto.AccountInfo;
import top.lidee.common.service.twice.management.CheckService;
import top.lidee.common.util.TokenUtil;
import top.lidee.framework.constant.NotesConstant;
import top.lidee.framework.enums.CommonExceptionEnum;
import top.lidee.framework.result.ResponseResult;
import top.lidee.repository.model.twice.vo.management.StoreApplicationVo;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/9/5 23:05
 */
@RestController
@RequestMapping("/backendApi/check/store")
public class CheckController {

    @Autowired
    private CheckService checkService;

    /**
     * 分页查询/根据id查询,审核成功/待审核/审核失败的基本信息
     */
    @ApiOperation(value = "分页查询审核成功/待审核/审核失败的基本信息", notes = NotesConstant.DEV)
    @RequestMapping(value = "/searchAllStatusInfo", method = RequestMethod.POST)
    public ResponseResult searchAllStatusInfo(HttpServletRequest request, @RequestBody Map<String,Object> params) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        return checkService.searchAllStatusInfo(params);
    }


    /**
     * 根据id查询,待审核
     */
    @ApiOperation(value = "根据id查询,待审核", notes = NotesConstant.DEV)
    @RequestMapping(value = "/searchWaitPass/{storeId}", method = RequestMethod.GET)
    public ResponseResult searchWaitPass(HttpServletRequest request,@PathVariable("storeId") Integer storeId) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        return checkService.searchWaitPass(storeId);
    }

    /**
     * 审核成功
     */
    @ApiOperation(value = "审核成功", notes = NotesConstant.DEV)
    @RequestMapping(value = "/storeApplicationSuccess", method = RequestMethod.POST)
    public ResponseResult storeApplicationSuccess(HttpServletRequest request,@RequestBody @Validated(StoreApplicationVo.success.class) StoreApplicationVo dto) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        return checkService.storeApplicationSuccess(dto,accountInfo);
    }


    /**
     * 审核失败
     */
    @ApiOperation(value = "审核失败", notes = NotesConstant.DEV)
    @RequestMapping(value = "/storeApplicationFila", method = RequestMethod.POST)
    public ResponseResult storeApplicationFila(HttpServletRequest request,@RequestBody @Validated(StoreApplicationVo.fila.class) StoreApplicationVo vo) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        return checkService.storeApplicationFila(vo,accountInfo);
    }


}
